package com.yqyd.quartz.task;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.yqyd.common.core.redis.RedisCache;
import com.yqyd.common.utils.WechatUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 定时任务调度(电匠院)
 * 
 * @author Dhq
 */
@Component("DJY")
public class DJYTask
{
    private final static String DJY_API = "http://www.dianjiangyuan.com";
    private final static String DJY_LOGIN_API = DJY_API +"/prod-api/login";
    private final static String ACCOUNT = "18268678185";
    private final static String PASSWORD = "123456";

    @Resource
    private RedisCache redisCache;

    public void Token()
    {
//        Map<String, Object> params = new HashMap<>();
//        params.put("username", ACCOUNT);
//        params.put("password", PASSWORD);

        String params = "{\"username\":\"" + ACCOUNT+ "\",\"password\":\"" + PASSWORD + "\"}";
        JSON response = JSONUtil.parse(HttpUtil.post(DJY_LOGIN_API, params));
        // 请求成功
        if (response.getByPath("code").toString().equals("200")) {
            String token = response.getByPath("token").toString();
            redisCache.setCacheObject("DJY_token", "Bearer " + token);
        }

    }
}
